﻿@model VietPremier.Areas.AdminCP.Models.Background
@{
    ViewBag.Title = "Edit";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}

<script type="text/javascript" src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")"></script>
<script type="text/javascript"  src="@Url.Content("~/ckeditor/ckeditor.js")"></script>
<script type="text/javascript" src="@Url.Content("~/ckfinder/ckfinder.js")"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        $('#nofSuccess').hide(); // an thong bao
        $('#nofError').hide();

        readyValue();
    });
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.search);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function readyValue() {
    }
    function alertMsg(msg) {
        $('#nofSuccess').hide();
        $('#nofError').show();
        $('#msgNofError').text(msg);
    }
    function getFileExtension(filename) {
        var ext = /^.+\.([^.]+)$/.exec(filename);
        return ext == null ? "" : ext[1];
    }
    function is_int(value) {
        for (i = 0; i < value.length; i++) {
            if ((value.charAt(i) < '0') || (value.charAt(i) > '9')) return false
        }
        return true;
    }


    function checkField() {
        var image = $("#Image").val();
        if (image == null || image == "") {

        }
        else {
            var ext = image.substring((Math.max(0, image.lastIndexOf(".")) || image.length) + 1);
            ext = ext.toLowerCase();

            if (ext != "jpg" && ext != "jpeg" && ext != "gif" && ext != "png") {

                msg = "! Upload an image file with format jpg, jpeg, gif or png";
                alertMsg(msg);
                $("#Image").css("border", "1px solid red");
                return false;
            }
        }

        return confirm("Do you want to continue to Edit this Image?");
    }

</script>

@{
    if (!string.IsNullOrEmpty(TempData["EditSuccessfully"] as string))
    {
        var getInfo = TempData["EditSuccessfully"].ToString();
        
        <script type="text/javascript">
            jQuery(document).ready(function () {
                checkEdit();
            });
            function checkEdit() {
                msg = '@getInfo';
                $('#nofError').hide();
                $('#nofSuccess').show();
                $('#msgNofSuccess').text(msg);
                return false;
            }
        </script>
    }
}

<div class="maincontentinner">

    <ul class="maintabmenu">
        
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->

    <form id="formCreate" class="stdform stdform2" method="post" action="#" enctype="multipart/form-data">
        <div class="contenttitle radiusbottom0">
            <h2 class="table"><span>Chỉnh sửa thông tin Background</span></h2>
        </div>
        <!--contenttitle-->

        <p hidden="hidden">
            <label>ID</label>
            <span class="field">
                <input type="text" name="Id" id="Id" class="longinput" readonly="readonly" value="@Model.ID"/></span>
        </p>
        
        <p>
            <label>Image</label>
             @{
        var imageFile = "~/Content/cssFrontEnd/images/";
        if (Model.Image != null)
        {
            imageFile += Model.Image;
        }
        else
        {
            imageFile += "no-photo.jpg";
        }
            }
            <span class="field">
                <img id="CurrentImage" src= "@Url.Content(imageFile)"  alt="" style="height: 100px; width: 100px" /></span>
        </p>
        <p>
            <label>Change Image</label>
            <span class="field">
                <input type="file" name="Image" id="Image" />
            </span>
        </p>

        <p>
            <label>Show</label>
            <span class="field">
                <select id="Show" name="Show">
                    @if (Model.Show == true)
                    {
                        <option selected value="True">True</option>
                        <option value="False">False</option>
                    }
                    else
                    {
                        <option value="True">True</option>
                        <option selected value="False">False</option>
                    }
                </select>
            </span>
        </p>

        <p class="stdformbutton">
            <input type="submit" value="Accept" onclick="return checkField()" />
            <input type="submit" value="Back" onclick="javascript: history.back(); return false" />
        </p>

    </form>
    <br clear="all" />

</div>
<!--maincontentinner-->

